package com.ws.universal.tools;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.Response;
import com.ws.universal.tools.utils.AppUtils;
import com.ws.universal.tools.utils.CacheUtils;
import com.ws.universal.tools.utils.StringUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class OrrorLog {
    public static void updateLog(String throwable) {
        HttpHeaders headers = new HttpHeaders();
        Map<String, String> params = new HashMap<>();
        params.put("appName", "ZDHX_AD");
        params.put("version", StringUtils.getString(AppUtils.getAppVersionCode()));
        params.put("sn", CacheUtils.getString("serial_number"));
        params.put("ocode", CacheUtils.getString("ocode"));
        params.put("base_url", CacheUtils.getString("base_url"));
        params.put("log", throwable);
        //LogcatUtils.e(" updateLog " + throwable);

        OkGo.<String>post("https://screen_log.w-dian.cn/cloud/screen/screenLog").params(params).headers(headers).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {

                if (response != null && !StringUtils.isEmpty(response.body())) {
                    String body = response.body().replaceAll("http:", "https:");
                    //LogcatUtils.e(" body post " + JSONFormat.format(body));
                    try {
                        JSONObject object = new JSONObject(body);
                        int code = object.optInt("code");
                        String msg = object.optString("msg");

                    } catch (JSONException e) {
                        e.printStackTrace();

                        //LogcatUtils.e("ws post  catch  getMethod listener.onError()");
                    }
                }

            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);


            }
        });
    }


}
